<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>课程管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./lib/layui/css/layui.css" />
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script th:inline="none">
        layui.use(["layer","table"],function() {
            var layer = layui.layer;
            var table = layui.table;
            table.render({
                elem: "#lessons",
                url: "lessonlists",
                page: true,
                toolbar: '#toolbarDemo',
                limit: 5,
                cols: [[ //表头
                    {field: 'id', title: '编号', width: 100, sort: true}
                    , {field: 'name', title: '课程名称', width: 180}
                    , {title: "操作", width: 200, toolbar: "#barDemo"}
                ]]
            })
            table.on('toolbar(lessonstab)',function (obj){
                if(obj.event=="add"){
                    layer.open({
                        type:2,
                        title:"添加课程",
                        area:["650px","500px"],
                        content:"toaddlesson"
                    })
                }
            })
            table.on('tool(lessonstab)',function (obj){
                if(obj.event=="update"){
                    layer.open({
                        type:2,
                        title:"修改课程",
                        area:["650px","500px"],
                        content:"toupdatelesson?id="+obj.data.id,
                    })
                }else if(obj.event=="delete"){
                    layer.confirm('您确定要删除该数据吗？', {
                        btn: ['确定', '取消']
                    }, function(index, layero){
                        $.ajax({
                            url:"deletelesson",
                            data:{"id":obj.data.id},
                            type:"post",
                            dataType:"json",
                            success:function(dataJson){
                                if(dataJson.code==200){
                                    location.reload();
                                }else{
                                    layer.msg(dataJson.msg);
                                }
                            }
                        })
                    }, function(index){

                    })
                }
            })
        })
    </script>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
        </div>

    </script>
    <script type="text/html" id="barDemo">

        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="update">修改</button>
        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">删除</button>

    </script>
</head>
<body>
<table id="lessons" lay-filter="lessonstab"></table>
</body>
</html>
